using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ICP_MS;

public class FormCanType : Form
{
	public string path = Application.StartupPath + "//iMassConfig//Interface.txt";

	private IContainer components = null;

	private RadioButton rdbtnCanet;

	private RadioButton rdbtn9820;

	private Button btnOk;

	private RadioButton rdbtnCanAdlink;

	private RadioButton rdbtnPCIE;

	private RadioButton rdBtn9810;

	private RadioButton rdbtnNetTCP;

	private Label label1;

	public int CanType { get; set; }

	public FormCanType()
	{
		InitializeComponent();
	}

	private void btnOk_Click(object sender, EventArgs e)
	{
		try
		{
			using StreamWriter sw = new StreamWriter(path, append: false);
			sw.WriteLine(CanType.ToString());
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
		base.DialogResult = DialogResult.OK;
	}

	private void FormCanType_Load(object sender, EventArgs e)
	{
		using (StreamReader sr = File.OpenText(path))
		{
			try
			{
				CanType = int.Parse(sr.ReadLine());
				switch (CanType)
				{
				case 0:
					rdbtnCanet.Checked = true;
					break;
				case 1:
					rdbtn9820.Checked = true;
					break;
				case 2:
					rdbtnPCIE.Checked = true;
					break;
				case 3:
					rdbtnCanAdlink.Checked = true;
					break;
				case 4:
					rdBtn9810.Checked = true;
					break;
				case 5:
					rdbtnNetTCP.Checked = true;
					break;
				}
			}
			catch (Exception)
			{
				CanType = 0;
			}
		}
		ApplyResources();
	}

	private void rdbtnCanet_CheckedChanged(object sender, EventArgs e)
	{
		if (rdbtnCanet.Checked)
		{
			CanType = 0;
		}
		else if (rdbtn9820.Checked)
		{
			CanType = 1;
		}
		else if (rdbtnPCIE.Checked)
		{
			CanType = 2;
		}
		else if (rdbtnCanAdlink.Checked)
		{
			CanType = 3;
		}
		else if (rdBtn9810.Checked)
		{
			CanType = 4;
		}
		else if (rdbtnNetTCP.Checked)
		{
			CanType = 5;
		}
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormCanType.Title.Text");
		label1.Text = Lang.Txt("FormCanType.Tip.Text");
		btnOk.Text = Lang.Txt("FormCanType.Button.OK.Text");
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.rdbtnCanet = new System.Windows.Forms.RadioButton();
		this.rdbtn9820 = new System.Windows.Forms.RadioButton();
		this.btnOk = new System.Windows.Forms.Button();
		this.rdbtnCanAdlink = new System.Windows.Forms.RadioButton();
		this.rdbtnPCIE = new System.Windows.Forms.RadioButton();
		this.rdBtn9810 = new System.Windows.Forms.RadioButton();
		this.rdbtnNetTCP = new System.Windows.Forms.RadioButton();
		this.label1 = new System.Windows.Forms.Label();
		base.SuspendLayout();
		this.rdbtnCanet.AutoSize = true;
		this.rdbtnCanet.Checked = true;
		this.rdbtnCanet.Location = new System.Drawing.Point(49, 81);
		this.rdbtnCanet.Margin = new System.Windows.Forms.Padding(4);
		this.rdbtnCanet.Name = "rdbtnCanet";
		this.rdbtnCanet.Size = new System.Drawing.Size(115, 20);
		this.rdbtnCanet.TabIndex = 1;
		this.rdbtnCanet.TabStop = true;
		this.rdbtnCanet.Text = "CANNET-TCP";
		this.rdbtnCanet.UseVisualStyleBackColor = true;
		this.rdbtnCanet.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.rdbtn9820.AutoSize = true;
		this.rdbtn9820.Location = new System.Drawing.Point(187, 81);
		this.rdbtn9820.Margin = new System.Windows.Forms.Padding(4);
		this.rdbtn9820.Name = "rdbtn9820";
		this.rdbtn9820.Size = new System.Drawing.Size(84, 20);
		this.rdbtn9820.TabIndex = 2;
		this.rdbtn9820.Text = "PCI-9820I";
		this.rdbtn9820.UseVisualStyleBackColor = true;
		this.rdbtn9820.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.btnOk.Location = new System.Drawing.Point(187, 245);
		this.btnOk.Margin = new System.Windows.Forms.Padding(4);
		this.btnOk.Name = "btnOk";
		this.btnOk.Size = new System.Drawing.Size(100, 31);
		this.btnOk.TabIndex = 3;
		this.btnOk.Text = "确定";
		this.btnOk.UseVisualStyleBackColor = true;
		this.btnOk.Click += new System.EventHandler(btnOk_Click);
		this.rdbtnCanAdlink.AutoSize = true;
		this.rdbtnCanAdlink.Location = new System.Drawing.Point(49, 179);
		this.rdbtnCanAdlink.Margin = new System.Windows.Forms.Padding(4);
		this.rdbtnCanAdlink.Name = "rdbtnCanAdlink";
		this.rdbtnCanAdlink.Size = new System.Drawing.Size(103, 20);
		this.rdbtnCanAdlink.TabIndex = 4;
		this.rdbtnCanAdlink.Text = "CAN-ADLink";
		this.rdbtnCanAdlink.UseVisualStyleBackColor = true;
		this.rdbtnCanAdlink.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.rdbtnPCIE.AutoSize = true;
		this.rdbtnPCIE.Location = new System.Drawing.Point(49, 130);
		this.rdbtnPCIE.Margin = new System.Windows.Forms.Padding(4);
		this.rdbtnPCIE.Name = "rdbtnPCIE";
		this.rdbtnPCIE.Size = new System.Drawing.Size(90, 20);
		this.rdbtnPCIE.TabIndex = 5;
		this.rdbtnPCIE.Text = "PCIE-9221";
		this.rdbtnPCIE.UseVisualStyleBackColor = true;
		this.rdbtnPCIE.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.rdBtn9810.AutoSize = true;
		this.rdBtn9810.Location = new System.Drawing.Point(187, 130);
		this.rdBtn9810.Margin = new System.Windows.Forms.Padding(4);
		this.rdBtn9810.Name = "rdBtn9810";
		this.rdBtn9810.Size = new System.Drawing.Size(84, 20);
		this.rdBtn9810.TabIndex = 6;
		this.rdBtn9810.Text = "PCI-9810I";
		this.rdBtn9810.UseVisualStyleBackColor = true;
		this.rdBtn9810.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.rdbtnNetTCP.AutoSize = true;
		this.rdbtnNetTCP.Location = new System.Drawing.Point(187, 179);
		this.rdbtnNetTCP.Margin = new System.Windows.Forms.Padding(4);
		this.rdbtnNetTCP.Name = "rdbtnNetTCP";
		this.rdbtnNetTCP.Size = new System.Drawing.Size(80, 20);
		this.rdbtnNetTCP.TabIndex = 4;
		this.rdbtnNetTCP.Text = "Net-TCP";
		this.rdbtnNetTCP.UseVisualStyleBackColor = true;
		this.rdbtnNetTCP.CheckedChanged += new System.EventHandler(rdbtnCanet_CheckedChanged);
		this.label1.BackColor = System.Drawing.SystemColors.Control;
		this.label1.ForeColor = System.Drawing.Color.Red;
		this.label1.Location = new System.Drawing.Point(4, 31);
		this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(341, 26);
		this.label1.TabIndex = 0;
		this.label1.Text = "请选择使用的CAN连接设备:";
		this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 16f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(335, 302);
		base.Controls.Add(this.rdBtn9810);
		base.Controls.Add(this.rdbtnPCIE);
		base.Controls.Add(this.rdbtnNetTCP);
		base.Controls.Add(this.rdbtnCanAdlink);
		base.Controls.Add(this.btnOk);
		base.Controls.Add(this.rdbtn9820);
		base.Controls.Add(this.rdbtnCanet);
		base.Controls.Add(this.label1);
		base.Margin = new System.Windows.Forms.Padding(4);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "FormCanType";
		base.ShowIcon = false;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "CAN类型";
		base.Load += new System.EventHandler(FormCanType_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
